﻿using System;
using System.Web.UI;
using Rob.SampleCode.MyApp.Core.Presentation;

namespace Rob.SampleCode.MyApp.Webforms
{
    public partial class GenerateError : Page, IGenerateErrorView
    {
        private GenerateErrorPresenter _presenter;

        protected override void OnInit(EventArgs e)
        {
            _presenter = new GenerateErrorPresenter(this);

            btnNIE.Click += btnNIE_Click;
            btnNRE.Click += btnNRE_Click;
            btnHandled.Click += btnHandled_Click;

            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) _presenter.Initialize();
        }

        public void NotifyUser(string message)
        {
            Response.Write(message);
        }

        private void btnNIE_Click(object sender, EventArgs e)
        {
            _presenter.ThrowNIE();
        }

        private void btnNRE_Click(object sender, EventArgs e)
        {
            _presenter.ThrowNullReferenceException();
        }

        private void btnHandled_Click(object sender, EventArgs e)
        {
            _presenter.HandleException();
        }
    }
}